package com.xcity.game.activity.oneyuan;

import java.util.Date;

import com.xcity.db.entity.Player;

import naga.x.util.NumberUtils;
import naga.x.util.StringUtils;
import naga.x.util.TimeUtils;

/**
 * 一元夺宝参与记录
 * @author yang.li
 *
 */
public class OneYuanActivityRecord {

	protected long id; // 玩家id
	protected int number; // 参与次数(累计)
	protected Date time; // 最后一次参与时间
	
	public OneYuanActivityRecord() {}
	
	public OneYuanActivityRecord(Player player) {
		this.id = player.getId();
		this.time = new Date();
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}
	
	public void addNumber(int n) {
		number += n;
	}
	
	@Override
	public String toString() {
		return id + "," + number + "," + TimeUtils.format(time);
	}
	
	public static OneYuanActivityRecord deserialize(String data) {
		String[] strs = StringUtils.split(data, ",");
		OneYuanActivityRecord ret = new OneYuanActivityRecord();
		ret.id = NumberUtils.parseLong(strs[0]);
		ret.number = NumberUtils.parseInt(strs[1]);
		ret.time = TimeUtils.parse(strs[2]);
		return ret;
	}
	
}
